<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>上传文件</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>文件</label>
                <div class="layui-input-inline">
                    <input id="cert" type="file"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input class="layui-btn" type="button" value="上传" onclick="upload();"/>
                </div>
            </div>
    </div>
</div>

<script>
    function upload(){
        var type = "file";          //后台接收时需要的参数名称，自定义即可
        var id = "cert";            //即input的id，用来寻找值
        var formData = new FormData();
        formData.append(type, $("#"+id)[0].files[0]);    //生成一对表单属性
        $.post({
            url: '/upload',
            data: formData,
            processData: false,
            contentType: false,
            success: function (res) {
                if (res != null) {
                    layer.msg(res.msg,{icon:res.code,time:2000});
                }else {
                    layer.msg('返回消息为空',{icon:7, time: 2000});
                }

            },error:function () {
                layer.msg('未知错误',{icon:3, time: 2000});
            }
        });
    }
</script>
</body>

</html>